<?php
class Settings_PHP{
	private $_settings = array();
	private static $mysetting;
	static function getSettings(){
		//echo dirname(__FILE__);
		if(!isset(self::$mysetting)){
			self::$mysetting = new Settings_PHP();
			self::$mysetting->load(dirname(__FILE__).'/../../../config/myconfig.php');
			
		}
		return self::$mysetting;
	}
	
    function get($var){
      $var = explode('.', $var,2);
      $result = $this->_settings;
      foreach ($var as $key) {
                if (!isset($result[$key])) { return false; }
                $result = $result[$key];
      }
      return $result;
    }
    
	function load ($file) {
		if (file_exists($file) == false) { 
			exit('no found config/myconfig.php!');
			//return false; 
		}
	   
		//Include file
		include ($file);
		//销毁指定变量
		unset($file);   
		//返回所有已定义变量的列表,数组,变量包括服务器等相关变量,
		$vars = get_defined_vars(); 
		//通过foreach吧$file引入的变量给添加到$_settings这个成员数组中去.
		
		foreach ($vars as $key => $val) {
	         if ($key == 'this') continue;
	         $this->_settings[$key] = $val;
	         
		}
//		echo "<pre>";
//		print_r($this->_settings);
//		echo "</pre>";
	}
}
?>
